const nodemailer = require('nodemailer');
const config = require('../config');
const email = {
    sendIdCode(emailTo, idCode) {
        let transporter = nodemailer.createTransport(config.email);
        let message = {
            from: '3191359769@qq.com',
            to: emailTo,
            subject: '验证码',
            text: `${idCode}`,
        };
        return new Promise((resolve, reject) => {
            transporter.sendMail(message, function(err, info) {
                if (err) {
                    reject(err);
                }
                resolve(info);
            })
        });
    },
    // async test() {
    //     let email = '16302010012@fudan.edu.cn';
    //     let res = await this.sendIdCode(email, '2324');
    //     return res;
    // }
};
// 测试
// email.test().then((res) => {
//     console.log(res);
// }).catch((e) => {
//     console.log(e);
// });

module.exports = email;